package 除自身以外数组的乘积;

class Solution {
    public int[] productExceptSelf(int[] nums) {
        int len = nums.length;
        int[] f = new int[len];
        int[] g = new int[len];
        int[] answer = new int[len];
        f[0] = g[len - 1] = 1;
        for(int i = 1; i < len; i++){
            f[i] = f[i - 1] * nums[i - 1];
        }
        for(int i = len - 2; i >= 0; i--){
            g[i] = g[i + 1] * nums[i + 1];
        }
        for(int i = 0; i < len; i++){
            answer[i] = f[i] * g[i];
        }
        return answer;
    }
}